window.onload = function () {
    document.getElementById("administrative").className = "add-nav-active";
    document.getElementById("document-template").className = "add_class";
    document.getElementById("organizational_management_ul").style.display = "inline-block";
    document.getElementById("jiantou").className = "iconfont icon-jiantou-xia";
};


function click_ul() {
    if (document.getElementById("jiantou").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou").className = "iconfont icon-jiantou-xia";
        document.getElementById("organizational_management_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou").className = "iconfont icon-jiantou-shang";
        document.getElementById("organizational_management_ul").style.display = "none";
    }
}

function click_ul1() {
    if (document.getElementById("jiantou1").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou1").className = "iconfont icon-jiantou-xia";
        document.getElementById("gebruikersrol_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou1").className = "iconfont icon-jiantou-shang";
        document.getElementById("gebruikersrol_ul").style.display = "none";
    }
}

function click_ul2() {
    if (document.getElementById("jiantou2").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou2").className = "iconfont icon-jiantou-xia";
        document.getElementById("meeting_management_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou2").className = "iconfont icon-jiantou-shang";
        document.getElementById("meeting_management_ul").style.display = "none";
    }
}

function click_ul3() {
    if (document.getElementById("jiantou3").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou3").className = "iconfont icon-jiantou-xia";
        document.getElementById("issue_approval_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou3").className = "iconfont icon-jiantou-shang";
        document.getElementById("issue_approval_ul").style.display = "none";
    }
}


// 提交新建公文模版
function save_template(templateId) {
    templateId = templateId || "";
    var template_name = document.getElementById("template_name").value;         // 模版名称
    var file_header = editor.txt.html().replaceAll("&", "%26");                // 文件头
    var file_end = editor1.txt.html().replaceAll("&", "%26");                // 文件尾

    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/administrative/add_template.html", true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send("template_name="+String(template_name)+"&file_header="+String(file_header)+"&file_end="+String(file_end)+"&templateId="+templateId);
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                if (JsonDate["code"] === 200) {
                    alert("模版保存成功！");
                    window.location = "/administrative/document_template.html";
                }else {
                    alert("模版保存失败！")
                }
            }
        }
    };
}
